<?php
// incident_details.php - Show incident details
//
// SiT (Support Incident Tracker) - Support call tracking system
// Copyright (C) 2010 The Support Incident Tracker Project
// Copyright (C) 2000-2009 Salford Software Ltd. and Contributors
//
// This software may be used and distributed according to the terms
// of the GNU General Public License, incorporated herein by reference.
//

$permission = 61; // View Incident Details
require ('..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'core.php');
require (APPLICATION_LIBPATH . 'functions.inc.php');

require_once (APPLICATION_LIBPATH . 'billing.inc.php');

// This page requires authentication
require (APPLICATION_LIBPATH . 'auth.inc.php');

// External variables
$incidentid = cleanvar($_REQUEST['id']);
$id = $incidentid;

if ($_REQUEST['win'] == 'incomingview')
{
    $title = 'Incoming';
    $incidentid = '';
    include ('inc/ticket_html_top.inc.php');
    include (APPLICATION_INCPATH . 'incident_incoming.inc.php');
    exit;
}
elseif ($_REQUEST['win'] == 'jump')
{
    if (incident_owner($incidentid) > 0)
    {
        echo "<html><head>";
        echo "<script src='{$CONFIG['application_webpath']}scripts/prototype/prototype.js' type='text/javascript'></script>\n";
        echo "<script src='{$CONFIG['application_webpath']}scripts/webtrack.js' type='text/javascript'></script>\n";
        if (!empty($_GET['return']))
        {
            $return = cleanvar($_GET['return']);
            echo "</head><body onload=\"\"><a href=\"$return\">{$strPleaseWaitRedirect}</a>";
            echo "<script type='text/javascript'>\n//<![CDATA[\n";
            echo "var popwin = incident_details_window($incidentid,'win', true);\n";
            echo "if (!popwin) alert('{$strDidYourBrowserBlockPopupWindow}');\n";
            echo "else window.location='{$return}';\n";
            echo "\n//]]>\n</script>\n";
            echo "</body></html>";
        }
        else
        {
            // echo "</head><body onload=\"incident_details_window($incidentid,'win');window.location='{$_SERVER['HTTP_REFERER']}';\">{$strPleaseWaitRedirect}</body></html>";
            echo "</head><body onload=\"\"><a href=\"{$_SERVER['HTTP_REFERER']}\"{$strPleaseWaitRedirect}</a>";
            echo "<script type='text/javascript'>\n//<![CDATA[\n";
            echo "var popwin = incident_details_window($incidentid,'win', true);\n";
            echo "if (!popwin) alert('{$strDidYourBrowserBlockPopupWindow}');\n";
            //echo "else window.location='{$_SERVER['HTTP_REFERER']}';\n";
            echo "else history.go(-1);\n";
            echo "\n//]]>\n</script>\n";
            echo "</body></html>";
        }
    }
    else
    {
        // return without loading popup
        echo "<html><head>";
        echo "<script src='{$CONFIG['application_webpath']}scripts/prototype/prototype.js' type='text/javascript'></script>\n";
        echo "<script src='{$CONFIG['application_webpath']}scripts/webtrack.js' type='text/javascript'></script>\n";
        if (!empty($_GET['return']))
        {
            $return = cleanvar($_GET['return']);
            echo "</head><body onload=\"incident_details_window($incidentid,'win');window.location='{$return}';\"></body></html>";
        }
        else
        {
            echo "</head><body onload=\"incident_details_window($incidentid,'win');window.location='{$_SERVER['HTTP_REFERER']}';\"></body></html>";
        }
    }
    exit;
}
elseif ($_REQUEST['win'] == 'holdingview')
{
    $_REQUEST['win'] = 'incomingview';
    $title = $strIncoming;
    $incidentid='';
}

else
{
    $title = $strDetails;
}

// Check for asked incident ID
$sql = "SELECT id FROM {$dbIncidents} ";
$sql .= "WHERE id = {$id} ";
$result = mysql_query($sql);
if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
if (mysql_num_rows($result) == 0) {

    // Incident doesn't exist
    // FIXME better error message - CJ 21/3-10
    html_redirect("main.php", FALSE, $strNotApplicableAbbrev);

} else {

include ('inc/ticket_html_top.inc.php');

echo "
<table border=0 width=100% align=center>
	<tr>
		<td width=50%>
	
			<div class='ticket'>	
		
			<table>
				<tr>
					<td  rowspan=4 valign=top>";
					echo icon('site', 16, $strSites);
				echo "</td>
					<td >Lieu d'intervention </td><td >:&nbsp;{$site_name} {$site_department}</td>
				</tr>	
				<tr>
					<td >Local </td><td >:&nbsp;{$asset_room}</td>
				</tr>
				<tr>
					<td>Adresse </td><td >:&nbsp;{$site_adresse}</td>
				</tr>
				<tr>
					<td >Code Postal / Ville</td><td >:&nbsp;{$site_postcode} {$site_city}</td>
				</tr>
			</table>
		</div>
		</td>
		<td width=50%>
		<div class='ticket'>
			<table>
				<tr>
					<td rowspan=4 valign=top>";
					echo icon('user', 16, $strContacts);
			echo "</td>
					<td><b>Demandeur </b></td><td>: {$incident->forenames} {$incident->surname}</td>
				</tr>
				<tr>
					<td><b>Service </b></td><td>: {$contact_department}</td>
				</tr>
				<tr>
					<td><b>Tel</b></td><td>:&nbsp;{$incident->phone}</td>
				</tr>
				<tr>
					<td><b>Personne de contact </b></td><td>:{$ticket->alternate_contact}</td>
				</tr>
			</table>
		</div>
		</td>
	</tr>

	<tr>
		<td colspan=2><hr></td>
	</tr>
	<tr>
		<td width=50% valign=top>
		<div class=ticket_info>		
			<table>
				<tr>
					<td><b>Date de creation </b></td><td>:".ldate($CONFIG['dateformat_datetime'],$created_date)."</td>
				</tr>
				<tr>
					<td><b>Par </b></td><td>:".user_realname($created_by,TRUE)."</td>
				</tr>
				<tr>
					<td><b>Categorie </b></td><td>:";
					if ($software_name!='' OR $incident->productversion != '' OR $incident->productservicepacks!='')
						{
						echo "{$software_name}";
						if ($incident->productversion != '' OR $incident->productservicepacks!='')
							{
							echo " (".$incident->productversion;
									if ($incident->productservicepacks!='')
										echo $incident->productservicepacks;
							echo ")";
							}
						echo "</td>";
						}
					echo "
				</tr>
				<tr>
					<td><b>Priorit&eacute;</b></td><td>:".priority_icon($incident->priority)." ".priority_name($incident->priority)."</td>
				</tr>
			</table>
		</div>
		</td >
		<td width=50% valign=top>
		<div class=ticket_info>
			<table>
				<tr>
					<td><b>Date d'assignation </b></td><td>:{$assigned}</td>
				</tr>
				<tr>
					<td><b>{$strOwner}</b> </td><td>:<strong>".user_realname($incident->owner,TRUE)."</strong> </td>
				</tr>
				<tr>
					<td valign='top'><b>Temps restant</b> </td><td>:";
echo sprintf($strOpenForX, $opened_for)." ";
echo incidentstatus_name($incident->status);
if ($incident->status == STATUS_CLOSED) echo " (" . closingstatus_name($incident->closingstatus) . ")";
echo "<br />\n";

// Show sla target/review target if incident is still open
if ($incident->status != STATUS_CLOSED AND $incident->status != STATUS_CLOSING)
{
    if ($targettype != '')
    {
        if ($slaremain > 0)
        {
            echo sprintf($strSLAInX, $targettype, format_workday_minutes($slaremain));
        }
        elseif ($slaremain < 0)
        {
            echo " ".sprintf($strSLAXLate, $targettype, format_workday_minutes((0-$slaremain)));
        }
        else
        {
            echo " ".sprintf($strSLAXDueNow , $targettype);
        }
    }

    if ($reviewremain <= 0)
    {
        if ($reviewremain > -86400)
        {
            echo "<br />".icon('review', 16)." ".sprintf($strReviewDueAgo ,format_seconds(($reviewremain*-1) * 60));
        }
        else
        {
            echo "<br />".icon('review', 16)." {$strReviewDueNow}";
        }
    }
    if ($servicelevel->timed == 'yes')
    {
        echo "<br />";
        switch (count($num_open_activities))
        {
            case 0: //start
                echo "<a href='task_add.php?incident={$id}'>{$strStartNewActivity}</a>";
                break;
            case 1: //stop
                echo "<a href='view_task.php?id={$num_open_activities[0]}&amp;mode=incident&amp;incident={$id}'>{$strViewActivity}</a> | ";
                $sql = "SELECT * FROM `{$dbNotes}` WHERE link='10' AND refid='{$num_open_activities[0]}'";
                $result = mysql_query($sql);
                if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
                if (mysql_num_rows($result) >= 1)
                {
                    echo "<a href='task_edit.php?id={$num_open_activities[0]}&amp;action=markcomplete&amp;incident={$id}'>{$strStopActivity}</a>";
                }
                else
                {
                    // Notes needed before closure
                    echo $strActivityContainsNoNotes;
                }
                break;
            default:  //greyed out
                echo "<a href='tasks.php?incident={$id}'>{$strMultipleActivitiesRunning}</a>";
        }
    }
					
					
					
					echo "
					</td>
				</tr>
			</table>
		</div>
		</td>
	</tr>
	<tr>
		<td colspan=2><hr></td>
	</tr>
	<tr>
		<td colspan=2 align=center><b> Information :</b></td>
	</tr>
	<tr>
		<td colspan=2><hr></td>
	</tr>
	<tr>
		<td width=50% valign=top>
		<div class=ticket_info>		
			<table>
				<tr>
					<td><b>Objet : </b>{$incident->title}</td>
				</tr>
				<tr>
					<td>{$ticket->description}</td>
				</tr>
			</table>
		</div>
		</td>
	</tr>
	<tr>
		<td colspan=2><hr></td>
	</tr>
	<tr>
		<td colspan=2 align=center><b> Hardware Information :</b></td>
	</tr>
	<tr>
		<td colspan=2><hr></td>
	</tr>
				<tr>
					<td><b>Barcode ID</b> :</td><td> {$ticket->asset_id}</td>
				</tr>
				<tr>
					<td><b>Type :</b></td><td> {$asset_class}</td>
				</tr>
				<tr>
					<td><b>Modele :</b></td><td>{$asset_model}</td>
				</tr>
				<tr>
					<td><b>Serial Number :</b></td><td> {$asset_sn}</td>
				</tr>

				<tr>
					<td><b>Service :</b></td><td> {$asset_room}</td>
				</tr>				
	
	
</table>";



plugin_do('incident_details');

echo "</div>\n\n";

}

include (APPLICATION_INCPATH . 'incident_html_bottom.inc.php');
}
?>